#include "Entity.h"
CEntity::CEntity(void)
{
	this->m_unRefCount = 1;
}


CEntity::~CEntity(void)
{
}

void CEntity::Render(void)
{

}

void CEntity::Update(float fElapsedTime)
{
	this->m_fPosX += this->m_fVelX * fElapsedTime;
	this->m_fPosY += this->m_fVelY * fElapsedTime;
}

RECT CEntity::GetRect( void ) const
{
	// Create a rect using the object's position as the top left corner
	RECT rSelf = 
	{
		(LONG)GetPosX(),				(LONG)GetPosY(),
		(LONG)(GetPosX() + GetWidth()),	(LONG)(GetPosY() + GetHeight())
	};

	return rSelf;
}

bool CEntity::CheckCollision( IEntity* pOther )
{
	// Store bounding rects (for debugging)
	RECT rSelf = GetRect(), rOther = pOther->GetRect(), rOverlap;
	BOOL bColliding = IntersectRect( &rOverlap, &rSelf, &rOther );

	if( bColliding == TRUE )
	{
		// Could add generic collision response here
		return true;
	}
	else
		return false;
}

void CEntity::AddRef( void )
{
	++m_unRefCount;
}

void CEntity::Release( void )
{
	--m_unRefCount;
	if( m_unRefCount == 0 )
		delete this;
}